package ConwaysGameOfLife;

import java.awt.Color;
import java.awt.Point;
import java.util.ArrayList;


/**
 *
 * @author Bryan
 */

//This class is a simple cell which stores information about itself and neighbors
public class Cell {

    private Color myColor;
    private Point location;
    private boolean alive;
    //enlisted means the cell is being considered for birth
    private boolean enlisted;
    private Cell[] adjacentCells;
    private final WorldControlMediator med;

    public Cell(Point location, WorldControlMediator med, Color myColor, boolean alive) {
        this.med = med;
        this.myColor = myColor;
        this.location = location;
        this.alive = alive;
        this.enlisted = false;
    }
    //this should only be called once, stores neighbors in memory
    public void findAdjacentCells() {
        Cell[] reportedCells = new Cell[8];
        reportedCells[0] = med.getCell(new Point(location.x - 1, location.y - 1), med.getWorld());
        reportedCells[1] = med.getCell(new Point(location.x, location.y - 1), med.getWorld());
        reportedCells[2] = med.getCell(new Point(location.x + 1, location.y - 1), med.getWorld());
        reportedCells[3] = med.getCell(new Point(location.x - 1, location.y), med.getWorld());
        reportedCells[4] = med.getCell(new Point(location.x + 1, location.y), med.getWorld());
        reportedCells[5] = med.getCell(new Point(location.x - 1, location.y + 1), med.getWorld());
        reportedCells[6] = med.getCell(new Point(location.x, location.y + 1), med.getWorld());
        reportedCells[7] = med.getCell(new Point(location.x + 1, location.y + 1), med.getWorld());
        adjacentCells = reportedCells;
    }
    //reports all neighbors which are alive (good for checking on cell death)
    public int reportNumberOfLivingNeighbors() {
        int neighbors = 0;
        for (Cell possible : getAdjacentCells()) {
            if (possible.isAlive()) {
                neighbors++;
            }
        }
        return neighbors;

    }
    
    //getters and setters from here on

    public Color getMyColor() {
        return myColor;
    }

    public void setMyColor(Color myColor) {
        this.myColor = myColor;
    }

    public Point getLocation() {
        return location;
    }

    public void setLocation(Point location) {
        this.location = location;
    }

    public boolean isAlive() {
        return alive;
    }

    public void setAlive(boolean alive) {
        this.alive = alive;
    }

    public boolean isEnlisted() {
        return enlisted;
    }

    public void setEnlisted(boolean enlisted) {
        this.enlisted = enlisted;
    }

    public Cell[] getAdjacentCells() {

        return adjacentCells;
    }

    public void setAdjacentCells(Cell[] adjacentCells) {
        this.adjacentCells = adjacentCells;
    }

}
